// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

export enum pressType{
    color = 1,
    opacity = 2,
    showPic = 3
}

@ccclass
export default class pressMediator extends cc.Component {

    @property({type : cc.Component.EventHandler,displayName : "触发事件"})
    toolEvent : cc.Component.EventHandler[] = [];

    @property({type : cc.Enum(pressType),displayName : "按压的类型"})
    curPressType : pressType = pressType.color;

    onLoad () {
        this.node.on("touchstart",this.TouchStart,this);
    }

    TouchStart(){
        if(this.curPressType == pressType.color){
            this.node.color = cc.color(174,249,0);
            cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            this.node.off("touchstart",this.TouchStart,this);
        }else if(this.curPressType == pressType.opacity){
            this.node.getComponent(cc.PhysicsPolygonCollider).enabled = false;
            this.node.opacity = 100;
            this.node.off("touchstart",this.TouchStart,this);
        }else if(this.curPressType == pressType.showPic){
            // this.node.children[0].active = true;
            // this.node.off("touchstart",this.TouchStart,this);
            cc.Component.EventHandler.emitEvents(this.toolEvent, [this.node,this]);

        }
    }

}
